package cn.kys.modules.system.service.impl;


import cn.kys.modules.system.repository.ToolsRepository;
import cn.kys.modules.system.service.ToolsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.UUID;

@Service
public class ToolsServiceImpl implements ToolsService {

    @Autowired
    private ToolsRepository toolsRepository;
    private SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

    public String getUUID() {

        return UUID.randomUUID().toString().replace("-", "");
    }



    @Override
    public void filter() {
        List list = toolsRepository.findAllLand();
        for (int i=0;i<list.size();i++){
            Map map = (Map)list.get(i);
            String gid = map.get("gid").toString();
            String landid = getUUID();
            toolsRepository.updateLand(landid, gid);
            System.out.println(gid);
        }
    }

    @Override
    public void filterCrops() {
        List list = toolsRepository.findAllLand();
        for (int i=0;i<list.size();i++){
            Map map = (Map)list.get(i);
            String gid = map.get("gid").toString();
            List cropsList = new ArrayList();
            cropsList.add("小麦");
            cropsList.add("玉米");
            cropsList.add("棉花");
            cropsList.add("果蔬");
            int index = (int)(1+Math.random()*(4-1+1));
            toolsRepository.updateLandCrops(cropsList.get(index-1).toString(), gid);
            System.out.println(gid);
        }
    }
}
